﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;

namespace Manas.DynamicDeepZoom.Core
{
    public class LevelContainerStyleSelector : StyleSelector
    {
        public ILevelDefiner LevelDefiner { get; set; }

        public int Level { get; set; }

        public double ContainerHeight { get; set; }

        public double ContainerWidth { get; set; }

        public override System.Windows.Style SelectStyle(object item, System.Windows.DependencyObject container)
        {
            var current = LevelDefiner.Level;
            if (current < Level) return null;

            var multiplier = Math.Pow(2, (current - Level));
            return CreateStyle(ContainerWidth * multiplier, ContainerHeight * multiplier);
        }

        private Style CreateStyle(double width, double height)
        {
            var style = new Style();
            style.Setters.Add(new Setter(FrameworkElement.HeightProperty, height));
            style.Setters.Add(new Setter(FrameworkElement.WidthProperty, width));
            return style;
        }
    }
}
